package com.shenjies88.practice.baseframework.controller;

import jakarta.annotation.Resource;
import lombok.AllArgsConstructor;
import org.springframework.ai.embedding.EmbeddingRequest;
import org.springframework.ai.embedding.EmbeddingResponse;
import org.springframework.ai.ollama.OllamaEmbeddingModel;
import org.springframework.ai.ollama.api.OllamaOptions;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.RestController;

import java.util.List;

/**
 * @author by shenjies88
 * @since 2025/9/13 22:49
 */
@AllArgsConstructor
@RequestMapping("/embeddingModel")
@RestController
public class EmbeddingModelController {

    @Resource(name = "dsllmEmbedModel")
    private final OllamaEmbeddingModel dsllmEmbedModel;

    @GetMapping("/chat")
    public float[] chat(@RequestParam String msg) {
        EmbeddingResponse response = dsllmEmbedModel.call(new EmbeddingRequest(List.of(msg),
                OllamaOptions
                        .builder()
                        .truncate(false)
                        .build()));
        return response.getResult().getOutput();
    }
}
